home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
resource
/
c
/
getrusage
< prev
next >
Wrap
Text File
|
1996-11-09
|
4KB
|
106 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/getrusage,v $
* $Date: 1996/10/30 21:59:00 $
* $Revision: 1.4 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: getrusage,v $
* Revision 1.4 1996/10/30 21:59:00 unixlib
* Massive changes made by Nick Burret and Peter Burwood.
*
* Revision 1.3 1996/09/16 21:23:52 unixlib
* CL_0002 Nick Burret
* Minor changes to file handling
* Change most error numbers, and use in assembler sources (SJC)
* Various minor bug fixes and compatability changes.
*
* Revision 1.2 1996/05/06 09:01:33 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:29:28 simon
* Initial revision
*
* Written by Nick Burrett, 18 Feb 1996.
***************************************************************************/
static const char rcs_id[] = "$Id: getrusage,v 1.4 1996/10/30 21:59:00 unixlib Rel $";
#include <sys/resource.h>
#include <sys/unix.h>
#include <errno.h>
/* Return resource usage information on process indicated by WHO
and put it in *USAGE. Returns 0 for success, -1 for failure. */
int
getrusage (enum __rusage_who who, struct rusage *usage)
{
int time;
if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
{
errno = EINVAL;
return -1;
}
if (usage == 0)
return -1;
time = (int) clock ();
/* Since clock () returns all time the current program has been
running for, we shall not bother with the ru_stime structure. */
/* Time spend executing user instructions. */
usage->ru_utime.tv_sec = time / 100;
/* Separate the centiseconds from the seconds and then convert
to microseconds. */
usage->ru_utime.tv_usec = (time - ((int)(time / 100) * 100)) * 10000;
/* Time spend in operating system code on behalf of 'who'. */
usage->ru_stime.tv_sec = 0;
usage->ru_stime.tv_usec = 0;
/* The maximum residet set size used, in kilobytes i.e. the
maximum number of kilobytes that 'who' used in real memory
simultaneously. */
usage->ru_maxrss = 0;
/* Amount of memory used by text that was shared with other
processes. Expressed in kilobytes * ticks of execution. */
usage->ru_ixrss = 0;
/* The amount of unshared memory used in data.
Expressed as above. */
usage->ru_idrss = 0;
/* The amount of unshared memory used in stack space.
Expressed as above. */
usage->ru_isrss = 0;
/* The number of page faults which were serviced without
requiring any I/O. */
usage->ru_minflt = 0;
/* The number of page faults which were serviced by doing I/O. */
usage->ru_majflt = 0;
/* The number of times 'who' was swapped entirely out of main
memory. */
usage->ru_nswap = 0;
/* The number of times the file system had to read from the disk
on behalf of 'who'. */
usage->ru_inblock = __u->usage.ru_inblock;
/* The number of times the file system had to write to the disk
on behalf of 'who'. */
usage->ru_oublock = __u->usage.ru_oublock;
/* Number of IPC messages sent. */
usage->ru_msgsnd = 0;
/* Number of IPC messages received. */
usage->ru_msgrcv = 0;
/* Number of signals received. */
usage->ru_nsignals = __u->usage.ru_nsignals;
/* Number of times 'who' voluntarily invoked a context switch
(usually to wait for some service). */
usage->ru_nvcsw = 0;
/* The number of times an involuntary context switch took place
(because the time slice expired, or another process of higher
priority became runnable). */
usage->ru_nivcsw = 0;
return 0;
}